package com.carcenter.order.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carcenter.common.model.dto.SaveProductBrandDto;
import com.carcenter.common.page.MyPageData;
import com.carcenter.common.result.Result;
import com.carcenter.order.entity.CarBrands;
import com.carcenter.order.entity.ProductBrands;
import com.carcenter.order.service.IProductBrandsService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author car
 * @since 2025-07-16
 */
@RestController
@RequestMapping("/product-brands")
public class ProductBrandsController {
    @Autowired
    private IProductBrandsService productBrandsService;
    @PostMapping("/save")
    public Result save(SaveProductBrandDto saveProductBrandDto){
        ProductBrands productBrands = new ProductBrands();
        productBrands.setBrandName(saveProductBrandDto.getBrandName());
        productBrandsService.save(productBrands);
        return Result.ok();
    }

    //详情-返回：商品品牌表
    @GetMapping("/getProductDetail/{pageNum}/{pageSize}")
    public Result<?> getProductDetail(@PathVariable("pageNum") Integer pageNum,
                               @PathVariable("pageSize") Integer pageSize) {
        Page<ProductBrands> page = productBrandsService.getProductDetail(pageNum,pageSize);
        MyPageData data = new MyPageData(page.getTotal(),page.getRecords());
        return Result.ok(data);
    }

    @GetMapping("/getBrands")
    public Result getBrands(){
        List<ProductBrands> list = productBrandsService.list();
        return Result.ok(list);
    }


    //新增-品牌名
    @PostMapping("/add")
    public Result<?> add(@RequestBody ProductBrands productBrands) {
        productBrandsService.add(productBrands);
        return Result.ok();
    }

    //查询-id
    @GetMapping("/getById/{id}")
    public Result<?> getById(@PathVariable Integer id) {
        ProductBrands productBrands = productBrandsService.getById(id);
        return Result.ok(productBrands);
    }

    //修改-汽车品牌表
    @PutMapping("/update")
    public Result<?> update(@RequestBody ProductBrands productBrands) {
        productBrandsService.updateProduct(productBrands);
        return Result.ok();
    }

    //删除-id
    @DeleteMapping("/delete/{id}")
    public Result<?> delete(@PathVariable Integer id) {
        productBrandsService.removeProduct(id);
        return Result.ok();
    }
}
